package vn.bus.bk.adapter;

import java.util.ArrayList;

import vn.bus.bk.R;
import vn.bus.bk.object.ItemPlaceInfo;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListItemPlaceAdapter extends BaseAdapter{
    
    LayoutInflater inflater;
    private ArrayList<ItemPlaceInfo> listPlace;
    public ListItemPlaceAdapter(Activity activity,ArrayList<ItemPlaceInfo> array){
	this.listPlace = array;
	inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public int getCount() {
	// TODO Auto-generated method stub
	return listPlace.size();
    }

    public Object getItem(int arg0) {
	// TODO Auto-generated method stub
	return arg0;
    }

    public long getItemId(int arg0) {
	// TODO Auto-generated method stub
	return arg0;
    }

    public View getView(int position, View convertView, ViewGroup arg2) {
	// TODO Auto-generated method stub
	ItemHolder holder = new ItemHolder();
	if(convertView == null){
	    convertView = inflater.inflate(R.layout.item_row_place, null);
	    holder.nameTypePlace = (TextView)convertView.findViewById(R.id.tvTypePlace);
	    holder.imgTypePlace = (ImageView)convertView.findViewById(R.id.imgTypePlace);
	    convertView.setTag(holder);
	}
	
	ItemPlaceInfo i = listPlace.get(position);
	if(i !=null){
	    holder = (ItemHolder) convertView.getTag();
	    holder.imgTypePlace.setImageBitmap(i.getBitmap());
	    holder.nameTypePlace.setText("  "+i.getNamePlace());
	}
	return convertView;
    }
    
}


class ItemHolder{
    TextView nameTypePlace;
    ImageView imgTypePlace;
}
